<?php
include_once 'constants.php';
session_start();
if(!isset($_SESSION[$sessionLoginTag])){
	header('location:index.php');
	exit;
}
$lat = isset($_GET['lat'])?$_GET['lat']:null;
if($lat==null)return; 
$lng = isset($_GET['lng'])?$_GET['lng']:null;
if($lng==null)return; 
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Marker Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
<script type="text/javascript">
var lat = <?php echo $lat;?>;
var lng = <?php echo $lng;?>;
$(document).on('pageinit', function() {
	var myLatlng = new google.maps.LatLng(lat, lng);
	var myOptions = {
		zoom : 18,
		center : myLatlng,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
	var marker = new google.maps.Marker({
		position : myLatlng,
		map : map,
		draggable : true
	});
	google.maps.event.addListener(marker, 'drag', function() {
		lat = marker.position.lat();
		lng = marker.position.lng();
		$('#1').html(lat);
		$('#2').html(lng);
	});

});
function registerLoc(){
	var d = new Date();
	var offset = d.getTimezoneOffset()/100 - 1;
	$.ajax({
		type: "get",
		url: "registerLoc.php?off="+offset+"&lat="+lat+"&lng="+lng,
		async: false,
		success: function(msg){
			$('#msg').html("Location Saved");
		},
		error:function(xhr) {
			$('#msg').html(xhr.statusText);
		}	
	});
}
function freshIt(){
	window.location.replace("findMyLoc.php");
}
</script>
</head>
<body>
<div data-role="page" id='index'>
	<div data-role="header" data-position="fixed">
		<div data-role="navbar">
			<ul>
				<li><a href="" id="fix" onclick='registerLoc();' data-role="button">Post Location</a></li>
				<li><a href="" id="fresh" onclick='freshIt();' data-role="button">Refresh</a></li>
			</ul>
		</div>
	</div>		
	<div data-role="content">		
		<div id="msg" style="text-align:center;font-size:70%;">Point is draggable.</div>
		<div id="map_canvas" style="margin:auto;width:80%;height:320px;"></div>
		<div id='1'></div>
		<div id='2'></div>
	</div>
</div>
</body>
</html>



